﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VideoNetApplication.Common.Helper;

namespace VideoNetApplication.Common.Extension
{
 public  static  class StringExtension
    {
        /// <summary>
        /// 字符串为null或string.Empty时，则返回参数值

        /// </summary>
        /// <param name="value"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public static string ToEmptyOrDefaultValue(this string value, string defaultValue)
        {
            if (string.IsNullOrEmpty(value))
            {
                return string.Empty;
            }
            else
                return defaultValue;
        }


        /// <summary>
        /// 字符串为null转换为string.Empty
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string ToEmptyOrValue(this string obj)
        {
            return DataHelper.GetString(obj);
        }
        /// <summary>
        /// 数字为null转换为0
        /// </summary>
        /// <param name="obj"></param>                          
        /// <returns></returns>
        public static int ToEmptyOrNumValue(this int obj)
        {
            return DataHelper.GetInteger(obj);
        }       
    }
}
